package cn.getech.data.development.utils;

import cn.getech.data.development.dto.EsDto;
import cn.getech.data.development.dto.KuduDto;
import org.apache.kudu.client.KuduClient;
import org.apache.kudu.client.KuduException;
import org.apache.kudu.client.KuduSession;
import org.apache.kudu.client.ListTablesResponse;
import org.elasticsearch.client.RestHighLevelClient;

/**
 * @ClassName KuduUtil
 * @Description TODO
 * @Author Getech
 * @Date 2021/1/18 16:41
 */
public class KuduUtil {

    /**
     * @Description 获取kudu客户端
     * @Author  chengweiping
     * @Date   2021/1/12 14:33
     */
    public static KuduClient getKuduClient(KuduDto esDto){
        KuduClient client=null;
        KuduSession kuduSession=null;
        try{
            String ip=esDto.getIp();
            String portStr=esDto.getPort();
           // Integer port=Integer.parseInt(portStr);
            String KUDU_MASTER=ip+":"+portStr;
            System.out.println("Will try to connect to Kudu master at " + KUDU_MASTER);
            client =new KuduClient.KuduClientBuilder(KUDU_MASTER).defaultAdminOperationTimeoutMs(10000).defaultOperationTimeoutMs(10000).build();
            ListTablesResponse listTablesResponse=client.getTablesList();
        }catch (Exception e){
            e.printStackTrace();
            client=null;
        }finally {
           if(kuduSession!=null){
               try {
                   kuduSession.close();
               } catch (KuduException e) {
                   e.printStackTrace();
               }
           }
        }

        return client;
    }
}
